
import { connect } from 'react-redux' ;

import Dumb from '../views/counter';

import { INCREASE , DECREASE  } from '../actions/counter';

// Action
const increaseAction = { type: INCREASE }
const decreaseAction = { type: DECREASE }

// Map Redux state to component props
function mapStateToProps(state) {
    console.log( state );
    return {
        // 注意这里指定的属性名
        value: state.counter.value 
    }
}

// Map Redux actions to component props
function mapDispatchToProps(dispatch) {
    return {
        // 注意这里指定的属性名
        increaseHandler: () => {
            return dispatch(increaseAction);
        },
        decreaseHandler: () => {
            return dispatch(decreaseAction);
        }
    }
}

// 将UI组件(木偶组件)包裹成容器组件
const x = connect( mapStateToProps, mapDispatchToProps );
const Counter = x(Dumb);


export default Counter;